package com.nut.lmsc.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.nut.lmsc.api.req.CircleShopQueryReq;
import com.nut.lmsc.common.Result;
import com.nut.lmsc.entity.CircleShop;
import com.nut.lmsc.mapper.CircleShopMapper;
import com.nut.lmsc.service.CircleShopService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

@Slf4j
@Service
public class CircleShopServiceImpl implements CircleShopService {

    @Autowired
    private CircleShopMapper circleShopMapper;

    @Override
    public Result<List<CircleShop>> list(Integer circleId) {
        List<CircleShop> list = circleShopMapper.selectByCircleId(circleId);
        return Result.ok(list);
    }

    @Override
    public Result<IPage<CircleShop>> listPage(CircleShopQueryReq req) {
        IPage<CircleShop> list = circleShopMapper.listPage(req.newPage(), req.getCircleId(),
                req.getShopName(), req.getStatus());
        return Result.ok(list);
    }

    @Override
    public Result<CircleShop> getById(Integer id) {
        CircleShop circleShop = circleShopMapper.selectById(id);
        if (circleShop == null) {
            return Result.fail("未找到导航图片信息");
        }
        return Result.ok(circleShop);
    }

    @Override
    public Result add(CircleShop circleShop) {
        circleShopMapper.insert(circleShop);
        return Result.ok();
    }

    @Override
    public Result updateById(CircleShop circleShop) {
        circleShopMapper.updateById(circleShop);
        return Result.ok();
    }

    @Override
    public Result deleteByIds(Set<Integer> ids) {
        circleShopMapper.deleteBatchIds(ids);
        return Result.ok();
    }
}
